package com.manage.system.web.controller;

import com.manage.common.core.result.JsonResult;
import com.manage.common.core.valid.AddGroup;
import com.manage.common.core.valid.UpdateGroup;
import com.manage.common.log.annotation.OperateLog;
import com.manage.common.log.enums.BusinessType;
import com.manage.common.permissions.annotation.HasPermissions;
import com.manage.system.api.request.dict.DictDataAddOrEditParam;
import com.manage.system.api.service.ISysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangqing
 * @version V1.0
 * @description 字典类型控制层
 * @date 6/3/2021 12:49 PM
 */
@RestController
@RequestMapping("/dict-data")
@AllArgsConstructor
@Api(tags = "字典数据控制层", value = "SysDictDataController")
public class SysDictDataController {

    private final ISysDictDataService sysDictDataService;

    @ApiOperation("获取字典数据列表")
    @GetMapping(value = "/findDictDataList/{dictType}")
    public JsonResult findDictDataList(@PathVariable String dictType){
        return sysDictDataService.findDictDataList(dictType);
    }

    @ApiOperation("批量删除字典数据")
    @DeleteMapping("/batchDelDictData")
    @HasPermissions("system:dict:remove")
    @OperateLog(module ="字典管理",title = "删除字典数据", businessType = BusinessType.DELETE)
    public JsonResult batchDelDictData(@RequestBody List<Long> dictDataIds) {
        return sysDictDataService.batchDelDictData(dictDataIds);
    }

    @ApiOperation("添加字典数据")
    @PostMapping("/addDictData")
    @HasPermissions("system:dict:add")
    @OperateLog(module ="字典管理",title = "添加字典数据", businessType = BusinessType.INSERT)
    public JsonResult addDictData(@Validated({AddGroup.class}) @RequestBody DictDataAddOrEditParam dictDataAddOrEditParam) {
        return sysDictDataService.addDictData(dictDataAddOrEditParam);
    }

    @ApiOperation("编辑字典数据")
    @PutMapping("/editDictData")
    @HasPermissions("system:dict:edit")
    @OperateLog(module ="字典管理",title = "修改字典数据", businessType = BusinessType.UPDATE)
    public JsonResult editDictData(@Validated({UpdateGroup.class}) @RequestBody DictDataAddOrEditParam dictDataAddOrEditParam) {
        return sysDictDataService.editDictData(dictDataAddOrEditParam);
    }
}
